package com.zlk.algorithm.dataStructure.stack;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @program: algorithm
 * @ClassName TwoQueue2Stack
 * @description:
 * @author: slfang
 * @create: 2024-01-02 11:12
 * @Version 1.0
 **/
public class TwoQueue2Stack<T> {


    public Queue<T> queue;
    public Queue<T> help;

    public TwoQueue2Stack() {
        queue = new LinkedList<>();
        help = new LinkedList<>();
    }

    public void push(T value){
        queue.offer(value);
    }

    public T poll() {
        while (queue.size() > 1) {
            help.offer(queue.poll());
        }
        T ans = queue.poll();
        Queue<T> tmp = queue;
        queue = help;
        help = tmp;
        return ans;
    }



}
